const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
var glob= require('glob');
var files = glob.sync('./src/views/*.html');
var entry={};
var plugins=[];

files.forEach(function(item,i){
    var htmlName=item.slice(item.lastIndexOf("/")+1);  
    var name=htmlName.split(".")[0];
    entry[name]='./src/js/'+name+'.js';
    plugins.push(
        new HtmlWebpackPlugin(
            {
                template: item,
                filename:`views/${htmlName}`
            }
        )
    )
});


module.exports={
    entry:entry,
    output:{
        filename:"js/[name].[chunkhash:5].js",
        path:path.resolve(__dirname,'../dist'),
  },
  module:{
    rules:[
        {
              test: /\.js$/,
              exclude: /node_modules/,
              use: {
                loader: 'babel-loader'          
            }
        }, 
        {
            test: /\.css$/,
            use: [
                { loader: "style-loader" },
                { loader: "css-loader" }
            ]
        },
        {
            test: /\.less$/,
            use: [
                {loader: "style-loader"}, 
                {loader: "css-loader" }, 
                {loader: "less-loader"},
                {
                    loader: "style-resources-loader",
                    options:{
                        patterns: [
                            path.resolve(__dirname, '../src/css/variable.less')
                        ]
                    }
                }
            ],
            
        }
         
    ]
  },
  plugins:plugins
}
